# -*- coding=utf-8 -*-

# 读取.ini配置文件的模块
# 把.ini文件按照
# []
# 	key = value
# 	key = value
# 	key = value
# []
# 	key = value
# 	key = value
# ......
# 分为section和key, value这种方式存储
import ConfigParser;

if __name__ == '__main__':
	config = ConfigParser.ConfigParser();
	config.read("ConfigParser.ini");

	# ['xiaohong', 'xiaoming', 'article']
	print config.sections();

	# ['name', 'age', 'sex']
	print config.options("xiaohong");

	# [('name', 'xiaohong'), ('age', '20'), ('sex', 'boy')]
	print config.items("xiaoming");

	# xiaoming
	print config.get("xiaoming", "name");

	# 20
	print config.getint("xiaoming", "age");

	# 写操作
	config.set("DEFAULT", "name", "null");
	with open("ConfigParser.ini", "w") as f_config:
		config.write(f_config);